/*-------------------------------------------------
Map 数据结构

2010-06-17   create by tss  
---------------------------------------------------*/

/**
 * 声明一个Map 类
 */
var Map = function(){
	this.dataList = new Array();
};


/**
 * 数据对象
 */
var Data = function(key,value){
	
	this.key = key;
	this.value = value;
};


/**
 * 是否包含 键
 */
Map.prototype.containsKey = function(key){
	
	return this.getValue(key) != null;
};

/**
 * 获得值
 */
Map.prototype.getValue = function(key){
	
	var index = this.getIndex(key);
	if(index != -1){
		return this.dataList[index].value;
	}else{
		return null;
	}
};


/**
 * 获得下标
 */
Map.prototype.getIndex = function(key){
	
	for(var i = 0; i < this.dataList.length; i++){
		var d = this.dataList[0];
		if(key == d.key){
			return i;
		}
	}
	return -1;
};

/**
 * 存放
 */
Map.prototype.put = function(key,value,isAppend){
	
	var index = this.getIndex(key);
	var d = null;
	if(index != -1){
		d = this.dataList[index];
		d.key = key;
		if(isAppend != 'undefined' && isAppend){
			var oldValue = d.value;
			var typeStr = typeof(oldValue);
			if(typeStr == "string"){
				value += oldValue;
			}else if(typeStr == "number"){
				value = parseInt(value) + oldValue;
			}else if(typeStr == "object"){
				value = value.concat(oldValue);
			}
		}
		d.value = value;
	}else{
		d = new Data(key,value);
		this.dataList.push(d);
	}
	return d;
};

/**
 * 移除
 */
Map.prototype.remove = function(key){
	
	var index = this.getIndex(key);
	var len = this.dataList.length - 1;
	if(index != -1){
		while(index < len){
			this.dataList[index] = this.dataList[index+1];
			index++;
		}
		this.dataList.length = len;
		return true;
	}else{
		return false;
	}
};

/**
 * 清空数据
 * @return
 */
Map.prototype.clear = function(){
	this.dataList.length = 0;
};
